import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/components/index'
import Login from '@/components/login'
import Dashboard from '@/components/dashboard'
import BillingList from '@/components/billing_list'

Vue.use(Router)

const sitename = '電子契約システム'
const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'index',
      component: Index,
      meta: {
        title: 'インデックス'
      }
    },
    {
      path: '/login',
      name: 'login',
      component: Login,
      meta: {
        title: 'ログイン'
      }
    },
    {
      path: '/dashboard',
      name: 'dashboard',
      component: Dashboard,
      meta: {
        title: 'ダッシュボード'
      }
    },
    {
      path: '/billing_list',
      name: 'billing_list',
      component: BillingList,
      meta: {
        title: '請求一覧'
      }
    },
    {
      path: '*',
      redirect: '/'
    }
  ]
})

export default router

router.afterEach((to, from) => {
  if (to.meta && to.meta.title) {
    if (sitename !== '') {
      document.title = to.meta.title + ' - ' + sitename
    } else {
      document.title = to.meta.title
    }
  }
})
